package cmj.cloudmusic.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.MediaController;
import android.widget.VideoView;

import cmj.cloudmusic.R;

public class VedioActivity extends AppCompatActivity {
    public String net="http://192.168.43.191:8080/SchoolLife/任务详情%202016_10_22%2019_41_20.mp4";
//    public String net="http://localhost:8080/SchoolLife/%E4%BB%BB%E5%8A%A1%E8%AF%A6%E6%83%85%202016_10_22%2019_41_20.mp4";
    public String local;

    public VideoView videoView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vedio);
        local="android.resource://"+getPackageName()+"/"+R.raw.aaa;
        videoView= (VideoView) findViewById(R.id.video);
        playByVideoView();
    }
    //hello  厘米级
    /**
     * 1
     */
    public void palyBySystem(){
        Uri uri=Uri.parse(net);
        Intent intent= new Intent(Intent.ACTION_VIEW);

        intent.setDataAndType(uri,"vedio/*");

        startActivity(intent);
    }

    /**
     * 2
     */
    public void playByVideoView(){
        videoView.setMediaController(new MediaController(this));
        videoView.setVideoURI(Uri.parse(local));
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                videoView.start();
            }
        });
        videoView.requestFocus();
    }
}
